package com.ht.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ht.shortlink.project.dao.entity.LinkTodayStatsDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 *  短链接今日监控数据持久层
 */
public interface LinkTodayStatsMapper extends BaseMapper<LinkTodayStatsDO> {

    @Insert("INSERT INTO t_link_today_stats (gid, full_short_url, date, today_pv, today_uv, today_uip, create_time, update_time, del_flag) " +
            "VALUES (#{linkTodayStatsDO.gid}, #{linkTodayStatsDO.fullShortUrl}, #{linkTodayStatsDO.date}, #{linkTodayStatsDO.todayPv}, #{linkTodayStatsDO.todayUv}, #{linkTodayStatsDO.todayUip}, " +
            "NOW(), NOW(), 0) " +
            "ON DUPLICATE KEY " +
            "UPDATE today_pv = today_pv +  #{linkTodayStatsDO.todayPv}," +
            "       today_uv = today_uv + #{linkTodayStatsDO.todayUv}," +
            "       today_uip = today_uip + #{linkTodayStatsDO.todayUip}," +
            "       update_time = NOW();")
    void insertLinkTodayStats(@Param("linkTodayStatsDO") LinkTodayStatsDO linkTodayStatsDO);
}
